package cn.com.bluemoon.daps.api.sync.factory;

import cn.com.bluemoon.daps.api.sync.RemoteSyncService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.sync.vo.applypublish.ApplyPublishParam;
import cn.com.bluemoon.daps.sync.vo.applypublish.ApplyPublishResultVo;
import cn.com.bluemoon.daps.sync.vo.applypublish.ModelCompareVo;
import cn.com.bluemoon.daps.sync.vo.applypublish.TableApplyPublishReportVo;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Jarod.Kong
 * @date 2021/7/2 14:32
 */
@Slf4j
@Component
public class RemoteSyncServiceFallbackFactory implements FallbackFactory<RemoteSyncService> {
    @Override
    public RemoteSyncService create(Throwable throwable) {
        log.error("同步结构服务调用失败:{}", throwable.getMessage());
        return new RemoteSyncService() {

            /**
             * 申请发布-模型版本对比前-决策-最新模型表是否与语法问题-不为空则有语法问题
             *
             * @param modelId 模型id
             * @return 为空则语法正常，不为空则存在语法问题
             */
            @Override
            public ResultBean<List<TableApplyPublishReportVo>> modelTableLayerPredicate(String modelId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSync.PROD_SERVICE, "模型表语法检查失败");
            }

            /**
             * 模型申请发布-模型版本对比（最新版（new）vs最新已发布版（old）
             *
             * @param modelId       模型id
             * @param newVsOld      true 为最新版（new）对比 最新已发布版（old），false 为最新已发布版（old）对比 最新版（new）， 默认为true
             * @param forceOverride false 强制
             * @return ResultBean
             */
            @Override
            public ResultBean<List<ModelCompareVo>> compareModelVersion(String modelId, Boolean newVsOld, Boolean forceOverride) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSync.PROD_SERVICE, "模型对比结果生成失败");
            }

            @Override
            public ResultBean<ApplyPublishResultVo> compareModelVersionV2(String modelId, Boolean newVsOld, Boolean forceOverride) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSync.PROD_SERVICE, "模型对比结果生成失败V2");
            }

            /**
             * 申请发布-确认通过
             *
             * @param applyPublishParam 申请发布-通过
             * @return ResultBean
             */
            @Override
            public ResultBean<String> applyConfirmPass(ApplyPublishParam applyPublishParam) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSync.PROD_SERVICE, "申请发布-通过失败");
            }

            @Override
            public ResultBean<String> applyConfirmUnPass(ApplyPublishParam applyPublishParam) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSync.PROD_SERVICE, "申请发布-不通过失败");
            }

            /**
             * 申请发布-撤销
             *
             * @param applyPublishParam 申请发布-通过
             * @return ResultBean
             */
            @Override
            public ResultBean<String> applyRevert(ApplyPublishParam applyPublishParam) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiSync.PROD_SERVICE, "申请发布-撤销失败");
            }
        };
    }
}
